Terminate strncpy() buffers correctly
authorEmmanuele Bassi <ebassi@gnome.org>
Tue, 10 Apr 2018 13:51:27 +0000 (14:51 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Tue, 10 Apr 2018 13:54:45 +0000 (14:54 +0100)
commit14c8a603e3b307d2f247764a828d390980854b0d
tree10d8f95e6ce30d0b1313c4ca23b88c4fa1699555
parentadc0159bdb733eaa870b8e12a4a14547a8d96407
Terminate strncpy() buffers correctly

When using strncpy() with a buffer we need to account for the
terminating NUL character. GCC 8 started warning when using PPD_MAX_NAME
as the buffer length for strncpy() because the buffer we're copying into
has the same length — which means that the terminating NUL may be
skipped if the source string has a length of PPD_MAX_NAME.

The appropriate way to handle the case where we're copying a source with
a length bigger than of PPD_MAX_NAME is, as reported in the strncpy()
documentation, to copy `PPD_MAX_NAME - 1` bytes, and explicitly NUL
terminate the destination buffer. This has the additional benefit of
avoiding the compiler warning.
modules/printbackends/gtkprintbackendcups.c